using UnityEngine;

public class PresentButton : MonoBehaviour
{
	public UILabel coinText;

	private bool isButtonActive;

	private void OnEnable()
	{
		UpdateButton();
	}

	private void Update()
	{
		bool flag = GGPlayerSettings.instance.walletManager.isNextCoinsActive();
		if (flag != isButtonActive)
		{
			UpdateButton();
		}
		if (!flag)
		{
			SetTimeToButton();
		}
	}

	private void SetTimeToButton()
	{
		coinText.text = GGFormat.FormatTimeSpan(GGPlayerSettings.instance.walletManager.TimeTillNextCoinsActive());
	}

	private void UpdateButton()
	{
		isButtonActive = GGPlayerSettings.instance.walletManager.isNextCoinsActive();
		if (!isButtonActive)
		{
			SetTimeToButton();
		}
		else
		{
			coinText.text = "+" + GGPlayerSettings.instance.walletManager.FreeCoins();
		}
	}

	public void OnClick()
	{
		WalletManager walletManager = GGPlayerSettings.instance.walletManager;
		if (walletManager.isNextCoinsActive())
		{
			walletManager.CollectFreeCoins();
			UIDialog.instance.ShowOk("Free coins!", "Gift of " + walletManager.FreeCoins() + "(Coin) for you! Next gift available in " + GGFormat.FormatTimeSpan(walletManager.TimeTillNextCoinsActive()) + "minutes!", "Ok", null);
		}
		else
		{
			UIDialog.instance.ShowOk("Not Available", "Free coins available in " + GGFormat.FormatTimeSpan(walletManager.TimeTillNextCoinsActive()) + " minutes! Return then!", "Ok", null);
		}
	}
}
